<?php
class IndexController 
	extends Zend_Controller_Action 
{

	public function indexAction() {
	
//	    Zend_Debug::dump($this->getRequest()->getParams());
//	    Zend_Debug::dump($this->_helper->Layout());
//	    exit;
	    
	    $mapperC = Vs_Factory::mapper('Category');
	    $mapperQ = Vs_Factory::mapper('Question');
	    
	    $this->view->categories = $mapperC->getByParams();
	    $this->view->questions = $mapperQ->getTop();
	    
	    $this->view->questions->setCategory($this->view->categories);
	}
	 
	public function aboutAction()
	{
		$this->render('acerca');
	}
	
	public function conditionsAction()
	{
		$this->render('condiciones');
	}
	
	public function privacyAction()
	{
		$this->render('privacidad');
	}
	
	public function helpAction()
	{
		$this->render('ayuda');
	}
	
	public function faqAction()
	{
		$this->render('preguntas');
	}
	
	public function contactAction()
	{
		$config = Zend_Registry::get('configuration') ;

		$form = new Web_Form_Contact(array(
			'pubkey' => $config->recaptcha->pubkey,
			'privkey'=> $config->recaptcha->privkey
		));
		
		$form->setAction(		
			$this->getHelper('Url')->url(array(), 'contact')
		);
		
		if($this->getRequest()->isPost()){
			
			$data = $this->getRequest()->getPost();

			if ( $form->isValid($data)) {

				$data = $form->getValues();
				
				//Mail	
				$mailer = new Delivery_Model_Mailer;
				$mail = new My_Mail();
				
				
				$mail->nombre	= $data['nombre'];
				$mail->email	= $data['email'];
				$mail->telefono	= $data['telefono'];
				$mail->asunto	= $data['asunto'];
				$mail->mensaje	= $data['mensaje'];
				$mail->lang = $this->lang;
				$mail->headerType = 'default';
				
				
				$mail->setTo( $config->mail->admin );
				$mail->setReplyTo( $data['email'] );
				$mail->setSubject( $this->system .": " . $data['asunto'] );
				$mail->setScriptHtml('contacto.phtml', 'layout-html');
				
				$mailer->queue( $mail );	
				
				$this->getHelper('MyFlashMessenger')->addSuccess( $this->_helper->Translate('thankForContactUs'));
				return $this->getHelper('Redirector')->gotoRoute(array(), 'contact');	
							
			} else {
				
				$form->populate($data);
			
			}	
		} 		
		
		$this->view->form = $form;
		$this->render('contacto');
	}
	
	public function sitemapAction()
	{
		$mapper1 = Delivery_Model_Factory::mapper( 'Negocios' );
		$mapper2 = Delivery_Model_Factory::mapper( 'Direcciones' );
		$mapper3 = Delivery_Model_Factory::mapper( 'Tags' );
		$mapper4 = Delivery_Model_Factory::mapper( 'Ciudades' );
		
		$this->view->negocios	= $mapper1->all();
		$this->view->ciudades	= $mapper4->getByIds($mapper2->ciudades());
		
		$this->view->negociosPorTag = $this->view->tags = $mapper3->getLinked();
		
		$this->render('mapa-del-sitio');
	}
	
	public function addCommerceAction()
	{
		$this->render('agregar-negocio');
	}
	
	public function howWorkAction()
	{
		$this->render('como-funciona');
	}
	
	public function consumersBenefitsAction()
	{
		$this->render('beneficios-consumidores');
	}
	
	public function restaurantsBenefitsAction()
	{
		$this->render('beneficios-restaurantes');
	}
	
	
}